package com.demo.inner;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
import me.chanjar.weixin.cp.api.WxCpTagService;
import me.chanjar.weixin.cp.api.impl.WxCpDepartmentServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;

import java.util.List;
import java.util.Map;

/**
 * created by lanxinghua@2dfire.com on 2020/2/13
 * 企业内部开发：通讯录管理
 * https://work.weixin.qq.com/api/doc/90000/90135/90194
 */
public class InnerAddressBookDemo extends InnerBaseService{
    public static void main(String[] args) throws Exception{
        String userId = "ChenXingXing";
        userRead(userId);
//        userInDept(1L);
        userId2Openid(userId, agentId);
    }


    /**----------------------- 成员管理 -----------------------**/

    /**
     * 读取成员
     */
    public static void userRead(String userId) throws Exception{
        WxCpUser user = wxCpService.getUserService().getById(userId);
        System.out.println(JSONUtil.toJsonStr(user));
    }

    /**
     * 获取部门成员
     */
    public static void userInDept(Long deptId) throws Exception{
        List<WxCpUser> list = wxCpService.getUserService().listSimpleByDepartment(deptId, null, null);
        System.out.println();
    }

    /**
     * userid与openid互换
     */
    public static void userId2Openid(String userId, Integer agentId) throws Exception{
        Map<String, String> map = wxCpService.getUserService().userId2Openid(userId, agentId);
        System.out.println(JSONUtil.toJsonStr(map));
    }



    /**----------------------- 部门管理 -----------------------**/
    public static void dept() throws Exception {
        WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
        List<WxCpDepart> list = departmentService.list(1L);
        System.out.println(JSONUtil.toJsonStr(list));
    }



    /**----------------------- 标签管理 -----------------------**/
    public static void tag() throws Exception {
        WxCpTagService tagService = wxCpService.getTagService();
        tagService.listAll();
    }


}
